home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / precog2_1.lha / Precognition2_1 / src / src.lha / Precognition / SelectedObject.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-15  |  5.0 KB  |  195 lines

  1.  
  2. #include "SelectedObject.h"
  3. #include "pcgWindow.h"
  4. #ifndef __GNUC__
  5. #include <clib/exec_protos.h>
  6. #include <clib/intuition_protos.h>
  7. #include <clib/graphics_protos.h>
  8. #endif
  9. #ifdef __GNUC__
  10. #include <proto/exec.h>
  11. #include <proto/intuition.h>
  12. #include <proto/graphics.h>
  13. #endif
  14. #ifdef __SASC
  15. #include <proto/exec.h>
  16. #include <proto/intuition.h>
  17. #include <proto/graphics.h>
  18. #endif
  19. #include "amigamem.h"
  20. #include <stdio.h>
  21. #include "ImageBob.h"
  22. #include "BuilderMethods.h"  /* Add prototypes for InitImageBob & CleanUpImageBob -- EDB */
  23.  
  24.    void so_DrawHighlight(  RastPort       *rport,
  25.                            SelectedObject *si,
  26.                            Point           delta )
  27.    {
  28.       Point size, location;
  29.       USHORT xmin, xmax, ymin, ymax;
  30.  
  31.       if( si == NULL ) return;
  32.  
  33.       size     = Size( si->PObject );
  34.       location = Location( si->PObject );
  35.  
  36.       xmin = location.x + delta.x;
  37.       xmax = xmin + size.x-1;
  38.       ymin = location.y + delta.y;
  39.       ymax = ymin + size.y-1;
  40.  
  41.       SetDrMd( rport, COMPLEMENT );
  42.       RectFill( rport, xmin, ymin, xmax, ymax );
  43.    }
  44.  
  45.  
  46.    void so_DrawHighlights( RastPort       *rport,
  47.                            SelectedObject *si,
  48.                            Point           delta )
  49.    {
  50.  
  51.       for( ; si != NULL; si = si->Next )
  52.          so_DrawHighlight( rport, si, delta );
  53.    }
  54.  
  55.    SelectedObject *so_SelectPObject( SelectedObject **chain,
  56.                                     GraphicObject   *obj )
  57.    {
  58.       SelectedObject *prev_si = NULL;
  59.       SelectedObject *si      = NULL;
  60.       SelectedObject *new_si  = NULL;
  61.  
  62.       /* printf("Select object \"%s\", ", obj->PObjectName );  */
  63.       /* printf("nSelected=%d\n", self->nSelected );           */
  64.  
  65.       if( *chain )
  66.       {
  67.          for( si = *chain; si != NULL; si = si->Next )
  68.          {
  69.             /* printf("checking object \"%s\" for match to \"%s\"\n", */
  70.             /*   si->PObject->PObjectName, obj->PObjectName );        */
  71.  
  72.             if( si->PObject == obj )
  73.             {
  74.                /* printf("They match!\n"); */
  75.                return NULL; /* PObject is already selected. */
  76.             }
  77.  
  78.             prev_si = si;
  79.          }
  80.       }
  81.  
  82.       /* printf("No match\n"); */
  83.       if( new_si = (SelectedObject *)Amalloc( sizeof( SelectedObject ) ) )
  84.       {
  85.          new_si->Next   = NULL;
  86.          new_si->PObject = obj;
  87.  
  88.          if( *chain )
  89.          {
  90.             /* printf( "added selection to tail.\n" );  */
  91.             prev_si->Next = new_si;
  92.          }
  93.          else
  94.          {
  95.             /* printf( "This is the first selection.\n" ); */
  96.             *chain = new_si;
  97.          }
  98.  
  99.       }
  100.       else
  101.          printf( "Couldn't allocate new_si\n" );
  102.  
  103.       return new_si;
  104.    }
  105.  
  106.  
  107.  
  108.    void so_InitImages( SelectedObject  *object_chain,
  109.                        struct RastPort *rport,
  110.                        Point            offset )
  111.    {
  112.       SelectedObject *object;
  113.       Point           location;
  114.  
  115.       /* Get images of objects */
  116.       for( object  = object_chain;
  117.            object != NULL;
  118.            object  = object->Next )
  119.       {
  120.          if( InitImageBob( object->PObject, &object->iBob ) )
  121.          {
  122.             /* printf( "got image bob\n" ); */
  123.  
  124.             /* use Screen relative coordinates. */
  125.             location = Location( object->PObject );
  126.  
  127.             object->iBob.VSprite.X = offset.x + location.x;
  128.             object->iBob.VSprite.Y = offset.y + location.y;
  129.  
  130.             AddBob( &object->iBob.Bob, rport );
  131.             /* printf( "added bob to list.\n" );  */
  132.          }
  133.  
  134.       }
  135.    }
  136.  
  137.    void so_CleanUpImages( SelectedObject  *object_chain )
  138.    {
  139.       SelectedObject *object;
  140.  
  141.       /* Get images of objects */
  142.       for( object  = object_chain;
  143.            object != NULL;
  144.            object  = object->Next )
  145.       {
  146.          RemBob( &object->iBob.Bob );
  147.          CleanUpImageBob( object->PObject, &object->iBob );
  148.       }
  149.    }
  150.  
  151.  
  152.    void so_Drag( SelectedObject  *object_chain,
  153.                  pcgWindow       *pwindow,
  154.                  Point            mouse )
  155.  
  156.    {
  157.       struct RastPort *screen_rport;
  158.       struct ViewPort *screen_vport;
  159.       struct Window   *iwindow;
  160.       ULONG            IDCMPbuf;
  161.       Point            window_loc;
  162.  
  163.       iwindow        = iWindow( pwindow );
  164.       screen_rport   = &iwindow->WScreen->RastPort;
  165.       screen_vport   = &iwindow->WScreen->ViewPort;
  166.  
  167.  
  168.       /* translate 'mouse' into screen coordinates. */
  169.       window_loc     = Location( (struct GraphicObject *)pwindow );
  170.       mouse.x       += window_loc.x;
  171.       mouse.y       += window_loc.y;
  172.  
  173.       so_InitImages( object_chain, screen_rport, window_loc );
  174.  
  175.       IDCMPbuf = IDCMPFlags( (struct Interactor *)pwindow );
  176.       SetIDCMPFlags( pwindow, IDCMPbuf | MOUSEMOVE );
  177.  
  178.       Forbid();
  179.       iwindow->Flags |= RMBTRAP; /* right mouse trap. */
  180.       Permit();
  181.  
  182.       DrawGList( screen_rport, screen_vport ); /* draw bobs. */
  183.  
  184.  
  185.  
  186.       /*** clean up ****/
  187.       Forbid();
  188.       iwindow->Flags &= ~RMBTRAP; /* right mouse trap. */
  189.       Permit();
  190.  
  191.       SetIDCMPFlags( pwindow, IDCMPbuf );
  192.       so_CleanUpImages( object_chain );
  193.       DrawGList( screen_rport, screen_vport ); /* erase bobs. */
  194.  
  195.    }